#Boa:Frame:Frame_CriarEvento

import wx
import wx.lib.masked.timectrl
import wx.lib.masked.textctrl
from Class_ConexaoEventoInterface import *
from Class_GerenciadorEvento import *

def create(parent, Usuario):
    return Frame_CriarEvento(parent, Usuario)

[wxID_FRAME_CRIAREVENTO, wxID_FRAME_CRIAREVENTOBUTTON1, 
 wxID_FRAME_CRIAREVENTOBUTTON2, wxID_FRAME_CRIAREVENTOCHOICE1, 
 wxID_FRAME_CRIAREVENTOCHOICE2, wxID_FRAME_CRIAREVENTODATEPICKERCTRL1, 
 wxID_FRAME_CRIAREVENTOPANEL1, wxID_FRAME_CRIAREVENTOSTATICBOX1, 
 wxID_FRAME_CRIAREVENTOSTATICBOX2, wxID_FRAME_CRIAREVENTOSTATICBOX3, 
 wxID_FRAME_CRIAREVENTOSTATICLINE1, wxID_FRAME_CRIAREVENTOSTATICTEXT1, 
 wxID_FRAME_CRIAREVENTOSTATICTEXT2, wxID_FRAME_CRIAREVENTOSTATICTEXT3, 
 wxID_FRAME_CRIAREVENTOSTATICTEXT4, wxID_FRAME_CRIAREVENTOSTATICTEXT5, 
 wxID_FRAME_CRIAREVENTOSTATICTEXT6, wxID_FRAME_CRIAREVENTOTEXTCTRL1, 
 wxID_FRAME_CRIAREVENTOTIMECTRL1, wxID_FRAME_CRIAREVENTOWINDOW1, 
 wxID_FRAME_CRIAREVENTOWINDOW2, wxID_FRAME_CRIAREVENTOWINDOW3, 
] = [wx.NewId() for _init_ctrls in range(22)]

class Frame_CriarEvento(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME_CRIAREVENTO,
              name=u'Frame_CriarEvento', parent=prnt, pos=wx.Point(472, 178),
              size=wx.Size(673, 480),
              style=wx.DEFAULT_FRAME_STYLE | wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL,
              title=u'Frame_CriarEvento')
        self.SetClientSize(wx.Size(665, 447))

        self.panel1 = wx.Panel(id=wxID_FRAME_CRIAREVENTOPANEL1, name='panel1',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(665, 447),
              style=wx.TAB_TRAVERSAL)
        self.panel1.SetBackgroundColour(wx.Colour(249, 249, 249))

        self.window1 = wx.Window(id=wxID_FRAME_CRIAREVENTOWINDOW1,
              name='window1', parent=self.panel1, pos=wx.Point(40, 56),
              size=wx.Size(584, 80), style=0)
        self.window1.SetBackgroundColour(wx.Colour(239, 239, 239))

        self.staticBox1 = wx.StaticBox(id=wxID_FRAME_CRIAREVENTOSTATICBOX1,
              label=u'', name='staticBox1', parent=self.window1, pos=wx.Point(8,
              8), size=wx.Size(568, 64), style=0)

        self.staticText1 = wx.StaticText(id=wxID_FRAME_CRIAREVENTOSTATICTEXT1,
              label=u'Nome do Evento', name='staticText1', parent=self.window1,
              pos=wx.Point(16, 32), size=wx.Size(110, 17), style=0)
        self.staticText1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tempus Sans ITC'))

        self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME_CRIAREVENTOTEXTCTRL1,
              name='textCtrl1', parent=self.window1, pos=wx.Point(144, 32),
              size=wx.Size(408, 24), style=0, value=u'')
        self.textCtrl1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.window2 = wx.Window(id=wxID_FRAME_CRIAREVENTOWINDOW2,
              name='window2', parent=self.panel1, pos=wx.Point(40, 152),
              size=wx.Size(584, 120), style=0)
        self.window2.SetBackgroundColour(wx.Colour(239, 239, 239))

        self.staticBox2 = wx.StaticBox(id=wxID_FRAME_CRIAREVENTOSTATICBOX2,
              label=u'', name='staticBox2', parent=self.window2, pos=wx.Point(8,
              8), size=wx.Size(568, 48), style=0)

        self.staticText2 = wx.StaticText(id=wxID_FRAME_CRIAREVENTOSTATICTEXT2,
              label=u'Tipo', name='staticText2', parent=self.window2,
              pos=wx.Point(64, 24), size=wx.Size(29, 17), style=0)
        self.staticText2.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tempus Sans ITC'))

        self.choice1 = wx.Choice(choices=[], id=wxID_FRAME_CRIAREVENTOCHOICE1,
              name='choice1', parent=self.window2, pos=wx.Point(144, 24),
              size=wx.Size(368, 21), style=0)

        self.window3 = wx.Window(id=wxID_FRAME_CRIAREVENTOWINDOW3,
              name='window3', parent=self.panel1, pos=wx.Point(40, 288),
              size=wx.Size(584, 72), style=0)
        self.window3.SetBackgroundColour(wx.Colour(239, 239, 239))

        self.staticText3 = wx.StaticText(id=wxID_FRAME_CRIAREVENTOSTATICTEXT3,
              label=u'Data', name='staticText3', parent=self.window3,
              pos=wx.Point(24, 27), size=wx.Size(30, 17), style=0)
        self.staticText3.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tempus Sans ITC'))
        self.staticText3.Center(wx.VERTICAL)

        self.datePickerCtrl1 = wx.DatePickerCtrl(id=wxID_FRAME_CRIAREVENTODATEPICKERCTRL1,
              name='datePickerCtrl1', parent=self.window3, pos=wx.Point(88, 24),
              size=wx.Size(104, 24), style=wx.DP_SHOWCENTURY)
        self.datePickerCtrl1.Center(wx.VERTICAL)

        self.staticText4 = wx.StaticText(id=wxID_FRAME_CRIAREVENTOSTATICTEXT4,
              label=u'Hor\xe1rio', name='staticText4', parent=self.window3,
              pos=wx.Point(272, 24), size=wx.Size(58, 19), style=0)
        self.staticText4.SetFont(wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tempus Sans ITC'))

        self.timeCtrl1 = wx.lib.masked.timectrl.TimeCtrl(display_seconds=True,
              fmt24hr=False, id=wxID_FRAME_CRIAREVENTOTIMECTRL1,
              name='timeCtrl1', oob_color=wx.NamedColour('Yellow'),
              parent=self.window3, pos=wx.Point(368, 24), size=wx.Size(68, 25),
              style=0, useFixedWidthFont=True, value=u'00:00:00')
        self.timeCtrl1.SetFormat('24HHMM')
        self.timeCtrl1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Book Antiqua'))

        self.staticBox3 = wx.StaticBox(id=wxID_FRAME_CRIAREVENTOSTATICBOX3,
              label=u'', name='staticBox3', parent=self.window2, pos=wx.Point(8,
              64), size=wx.Size(568, 48), style=0)

        self.staticText5 = wx.StaticText(id=wxID_FRAME_CRIAREVENTOSTATICTEXT5,
              label=u'Faixa Etaria', name='staticText5', parent=self.window2,
              pos=wx.Point(40, 83), size=wx.Size(74, 17), style=0)
        self.staticText5.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tempus Sans ITC'))

        self.choice2 = wx.Choice(choices=[], id=wxID_FRAME_CRIAREVENTOCHOICE2,
              name='choice2', parent=self.window2, pos=wx.Point(144, 80),
              size=wx.Size(130, 21), style=0)

        self.staticText6 = wx.StaticText(id=wxID_FRAME_CRIAREVENTOSTATICTEXT6,
              label=u'Criar Novo Evento', name='staticText6',
              parent=self.panel1, pos=wx.Point(242, 8), size=wx.Size(181, 27),
              style=0)
        self.staticText6.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tempus Sans ITC'))
        self.staticText6.Center(wx.HORIZONTAL)

        self.staticLine1 = wx.StaticLine(id=wxID_FRAME_CRIAREVENTOSTATICLINE1,
              name='staticLine1', parent=self.panel1, pos=wx.Point(204, 40),
              size=wx.Size(256, 2), style=0)
        self.staticLine1.Center(wx.HORIZONTAL)

        self.button1 = wx.Button(id=wxID_FRAME_CRIAREVENTOBUTTON1,
              label=u'Criar', name='button1', parent=self.panel1,
              pos=wx.Point(392, 392), size=wx.Size(104, 40), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_FRAME_CRIAREVENTOBUTTON1)

        self.button2 = wx.Button(id=wxID_FRAME_CRIAREVENTOBUTTON2,
              label=u'Cancelar', name='button2', parent=self.panel1,
              pos=wx.Point(520, 392), size=wx.Size(104, 40), style=0)
        self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
              id=wxID_FRAME_CRIAREVENTOBUTTON2)

    def __init__(self, parent, Usuario):
        self._init_ctrls(parent)
        
        self.Usuario = Usuario
        self.ge = GerenciadorEvento()
        
        CEI = ConexaoEventoInterface()
        
        CEI.preencherChoiceTipos(self.choice1)
        CEI.preencherChoiceFaixas(self.choice2)
    
    #Botao de Cancelar Criacao do Evento
    def OnButton2Button(self, event):
        import Frame_PaginaUsuario
        Frame_PaginaUsuario.create(None, self.Usuario).Show()
        self.Close()


    #Botao "Criar Evento" 
    def OnButton1Button(self, event):
        
        Nome = self.textCtrl1.GetValue()
        
        Ano = self.datePickerCtrl1.GetValue().GetYear()
        Mes = self.datePickerCtrl1.GetValue().GetMonth()
        Dia = self.datePickerCtrl1.GetValue().GetDay()
        Data = '%s-%s-%s'%(Ano, Mes, Dia)
        
        Horario = str(self.timeCtrl1.GetValue())
        Tipo = self.choice1.GetStringSelection()
        FaixaEtaria = self.choice2.GetStringSelection()
        Organizador = self.Usuario
        
        NovoEvento = Evento(Nome, Data, Horario, Tipo, Organizador, FaixaEtaria)
        
        confirmacao = self.ge.CadastrarEvento(NovoEvento)
        
        if confirmacao == True:
            m = "Evento Cadastrado com Sucesso!"
            t = "Cadastro de Evento"
            wx.MessageBox(m,t,wx.OK)
            
            import Frame_PaginaUsuario
            Frame_PaginaUsuario.create(None, self.Usuario).Show()
            self.Close()
